package com.idriver.controller;

import com.idriver.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "DelStudentServlet", urlPatterns = "/delStudent")
public class DelStudentServlet extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String id = request.getParameter("id");
        StudentService service = new StudentService();
        int affectedRow = service.delStudent(Integer.parseInt(id));

        if (1 != affectedRow) {
            System.out.println("学生id错误, 无法删除!");
        }
        response.sendRedirect("main.jsp");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
